home *** CD-ROM | disk | FTP | other *** search
- Path: liberty.b23a.ingr.com!dpmikese
- From: dpmikese@ingr.com (Dave Mikesell)
- Newsgroups: comp.lang.c
- Subject: Re: How to use assert( )
- Date: Fri, 12 Apr 1996 12:37:50
- Organization: Intergraph
- Message-ID: <dpmikese.14.005EA7C0@ingr.com>
- References: <4kc3k7$dur@orion.cybercom.net> <316be48b.3354928@news.netvision.net.il> <4kiirb$hll@sparcserver.lrz-muenchen.de> <smryanDpqBv7.E56@netcom.com>
- NNTP-Posting-Host: liberty.b23a.ingr.com
- X-Newsreader: Trumpet for Windows [Version 1.0 Rev B final beta #4]
-
- In article <smryanDpqBv7.E56@netcom.com> smryan@netcom.com (@#$%!?!) writes:
- >Newsgroups: comp.lang.c
- >Path: b10.b10.ingr.com!news.ingr.com!news.msfc.nasa.gov!newsfeed.internetmci.com!howland.reston.ans.net!ix.netcom.com!netcom.com!smryan
- >From: smryan@netcom.com (@#$%!?!)
- >Subject: Re: How to use assert( )
- >Message-ID: <smryanDpqBv7.E56@netcom.com>
- >Organization: The Programmer formerly known as S M Ryan
- >X-Newsreader: TIN [version 1.2 PL1]
- >References: <4kc3k7$dur@orion.cybercom.net> <316be48b.3354928@news.netvision.net.il> <4kiirb$hll@sparcserver.lrz-muenchen.de>
- >Date: Fri, 12 Apr 1996 03:18:43 GMT
- >Lines: 14
- >Sender: smryan@netcom21.netcom.com
-
-
- >: The end user should never see the output of an assertion in an ideal
- >: world. One reason for this is that a final build should be translated
- >: with NDEBUG defined. The other (more optimistic) reason is, that all
- >: possible problems that make an assertion fail should have been
- >: detected during testing.
-
- >It is preferable to have the program fail mysteriously for the customer
- >with possibly the only opportunity to diagnose it gone.
-
- Not if you build in user-level debugging. For instance, your code could
- check for the existence of an environment variable defined in the user's
- environment - if it's there, you could write debug info somewhere that
- the user could get to and relay it to you. I prefer this method to firing
- an assertion and aborting the program. Of course, you could write your own
- assert macro and function that doesn't abort...it's not that hard:
-
- #ifdef DEBUG
- #define ASSERT(expr) if (expr) {} else _Assert(__FILE__, __LINE__)
- #else
- #define ASSERT(expr)
- #endif
-
- void _Assert(char *file, unsigned line)
- {
- fprintf(stderr, "\nAssertion failed: %s, line %d\n", file, line);
- }
-
- --
- Dave M.
-
-